home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / cdev / clrnxtwd.sit / Test code.c < prev    next >
C/C++ Source or Header  |  1989-11-03  |  3KB  |  162 lines

  1. /*
  2.  * NeXT WDEF testing code
  3.  */
  4.  
  5. #include <Global.h>
  6.  
  7. typedef struct {
  8.     int        jump;
  9.     long    add;
  10. } defRec, *defPtr, **defHdl;
  11.  
  12. defHdl        theDef;
  13. EventRecord    event;
  14. Boolean        hasQuit = false;
  15.  
  16. main()
  17. {
  18.     Boolean        gotEvent;
  19.     WindowPtr    window;
  20.     int            i;
  21.     Handle        menuBar;
  22.     Rect        wRect;
  23.     pascal long nextWDEF(/* variation, window, message, parameter */);
  24.  
  25.     InitGraf(&thePort);
  26.     InitCursor();
  27.     InitFonts();
  28.     InitWindows();
  29.     InitMenus();
  30.     TEInit();
  31.     InitDialogs(nil);
  32.  
  33.     MoreMasters();
  34.     MoreMasters();
  35.     
  36.     FlushEvents(everyEvent, 0);    /* flush toilet */
  37.     GetNextEvent(everyEvent, &event);
  38.     GetNextEvent(everyEvent, &event);
  39.     
  40.     theDef = (defHdl)GetResource('WDEF', 10);
  41.     (**theDef).jump = 0x4ef9;
  42.     (**theDef).add = (long)nextWDEF;
  43.     
  44.     menuBar = GetNewMBar(128);
  45.     SetMenuBar(menuBar);
  46.     DisposHandle(menuBar);
  47.     AddResMenu(GetMHandle(128), 'DRVR');
  48.     DrawMenuBar();
  49.     
  50.     SetRect(&wRect, 20, 60, 420, 360);
  51.     window = NewWindow((WindowPeek)nil, &wRect, "\pThis is obviously a very nice window.", true, 168, (WindowPeek)-1l, true, 0);
  52.     OffsetRect(&wRect, 40, 40);
  53.     window = NewCWindow(nil, &wRect, "\pThe 2nd window!", true, 168, -1l, true, 0);
  54.     
  55.     do {
  56.         SystemTask();
  57.         gotEvent = GetNextEvent(everyEvent, &event);
  58.         
  59.         if (gotEvent) {
  60.             switch(event.what) {
  61.             case mouseDown:
  62.                 DoMouseDown();
  63.                 break;
  64.             case updateEvt:
  65.                 DoUpdate((WindowPtr) event.message);
  66.                 break;
  67.             }
  68.         }
  69.     } while(!hasQuit);
  70. }
  71.  
  72. DoMouseDown()
  73. {
  74.     short        part;
  75.     WindowPtr    window;
  76.     long        growResult;
  77.     Rect        growRect;
  78.     
  79.     part = FindWindow(event.where, &window);
  80.     switch (part) {
  81.     case inMenuBar:
  82.         doMenu(MenuSelect(event.where));
  83.         break;
  84.     case inDrag:
  85.         DragWindow(window, event.where, &screenBits.bounds);
  86.         break;
  87.     case inContent:
  88.         if ( window != FrontWindow() )
  89.             SelectWindow(window);
  90.     case inGoAway:
  91.         SetPort(window);
  92.         if ( TrackGoAway(window, event.where) )
  93.             hasQuit = true;
  94.         break;
  95.     case inGrow:
  96.         SetPort(window);
  97.         SetRect(&growRect, 80, 60, 600, 500);
  98.         growResult = GrowWindow(window, event.where, &growRect);
  99.         if (growResult != 0)
  100.             SizeWindow(window, LoWord(growResult), HiWord(growResult), true);
  101.         break;
  102.     case inZoomIn:
  103.     case inZoomOut:
  104.         SetPort(window);
  105.         if ( TrackBox(window, event.where, part) ) {
  106.             EraseRect(&thePort->portRect);
  107.             ZoomWindow(window, part, window == FrontWindow());
  108.             InvalRect(&thePort->portRect);
  109.         }
  110.         break;
  111.     }
  112. }
  113.  
  114. doMenu(mChoice)
  115. long    mChoice;
  116. {
  117.     int            menuID, menuItem;
  118.     WindowPtr    window;
  119.     Rect        wRect;
  120.     
  121.     menuID = HiWord(mChoice);
  122.     menuItem = LoWord(mChoice);
  123.     window = FrontWindow();
  124.     
  125.     if (menuID == 129)
  126.         switch(menuItem) {
  127.         case 1: case 2: case 3: case 4: case 5:
  128.             DisposeWindow(window);
  129.             SetRect(&wRect, 60, 60, 360, 300);
  130.             window = NewWindow(nil, &wRect, "\pChanged.", true, 160+menuItem-1, (WindowPtr)-1l, true, 0l);
  131.             break;
  132.         case 6:
  133.             DisposeWindow(window);
  134.             SetRect(&wRect, 70, 70, 360, 300);
  135.             window = NewWindow(nil, &wRect, "\pBack again.", true, 168, (WindowPtr)-1l, true, 0l);
  136.             break;
  137.         case 8:
  138.             hasQuit = true;
  139.             break;
  140.     }
  141.     HiliteMenu(0);
  142. }
  143.  
  144. DoUpdate(window)
  145. WindowPtr    window;
  146. {
  147.     Rect    box;
  148.     
  149.     SetPort(window);
  150.     BeginUpdate(window);
  151.     if ( ! EmptyRgn(window->clipRgn) ) {
  152.         PenNormal();
  153.         EraseRgn(window->clipRgn);
  154.         SetRect(&box, 10, 10, 200, 200);
  155.         FillOval(&box, <Gray);
  156.         OffsetRect(&box, 10, -10);
  157.         FillOval(&box, &gray);
  158.         DrawGrowIcon(window);
  159.     }
  160.     EndUpdate(window);
  161. }
  162.